<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="entities.Comment"%> 
<jsp:useBean id="user" class="entities.User" scope="session"/>
<jsp:useBean id="event" class="entities.Event" scope="request"/>
<%--<jsp:useBean id="rateMoyenne" class="java.lang.Integer" scope="request"/> --%>
<jsp:useBean id="comments" class="java.util.Vector" scope="request"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:directive.page import="entities.*"/>
<%@include file="header.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script language="JavaScript">
	function add(){

		var idEvent=document.getElementById("idEvent").value;
		var idUser=document.getElementById("idUser").value;
		window.location.href="SerEvent?types=participer&idEvent="+idEvent+"&idParticipant="+idUser;
	}
	function noParticiper(){
		var idEvent=document.getElementById("idEvent").value;
		var idUser=document.getElementById("idUser").value;
		window.location.href="SerEvent?types=noparticiper&idEvent="+idEvent+"&idParticipant="+idUser;
		
	}
	function showMaps(){
		var place=document.getElementById("btnMap").value;
	
		window.open ("map.jsp?place="+place, "new windows", "height=400, width=400, top=300,left=400, toolbar=no,  menubar=no, scrollbars=no, resizable=no,location=no, status=no")  
	}

	
</script> 
</head>
<body>
	<% 
  		Event nEvent = (Event)request.getAttribute("nEvent");
	  	request.getSession().setAttribute("nEvent",nEvent); 
		String participerId=(String)request.getSession().getAttribute("id");
		String typesUser = (String)request.getAttribute("typesUser")==null?"":(String)request.getAttribute("typesUser");
		if(nEvent!=null){
  		
  	%>
  	<hr/>
 	<input  type="hidden" id="idEvent" value=<%=nEvent.getIdEvent()%>  >
 	<input  type="hidden" id="idUser" value=<%=participerId%>  >
  	<table>
	<tr>
    	<td>name</td>
    	<td><%=nEvent.getName() %></td>
    </tr>
    <tr>
    	<td>place</td>
    	<td><input type="button" id="btnMap" onclick="showMaps()" value="<%=nEvent.getPlace() %>"/></td>
   
    </tr>
     <tr>
    	<td>date</td>
    	<td><%=nEvent.getDate() %></td>
    </tr>
       <tr>
    	<td>hour</td>
    	<td><%=nEvent.getHour() %></td>
    </tr>
     <tr>
    	<td>nombre</td>
    	<td><%=nEvent.getNbParticipants() %></td>
    </tr>
     <tr>
    	<td>category</td>
    	<td><%=nEvent.getCategory().getName() %></td>
    </tr>
     <tr>
        <td>Promoteur</td>
    	<td><%=nEvent.getPromoters().getUser() %> </td>
    </tr>

      <tr>
    	<td>description</td>
    	<td><textarea  rows="10" id="contactus"  readonly name="des"><%=nEvent.getDescription() %></textarea></td>
    </tr>
   	
	</table>
	
	<hr/>
	
	
	<%} %>
	<input type="button" name="btnAdd" onclick="add()" value="Participer cet Event">
	
	<% 
			if("MyFutureEvents".equals(typesUser)){
    %>	
	<input type="button" name="btnNO" onclick="noParticiper()" value=" Ne pas Participer cet Event">
    <% 
		}
		if("MyOrganisedEvents".equals(typesUser)){
	%>
			<input type="button" name="btnDel" onclick="supprimer()" value="supprimer cet Event">
	<% 		
		}
	%>
	
	 <% //if (!(user.getUser() == null)) { 
		 String id = (String)request.getSession().getAttribute("id");
	 	if (id !=null) {
	 %>

            <fieldset>
            <h3>Commentez cet event</h3>

                <form action="CommentEvent" method="post">
                <p><label>Message</label><textarea name="message" cols="40" rows="5"></textarea></p>
                <p><input type="hidden" name="userId" value="<%=String.valueOf(id)%>"/>
                <input type="hidden" name="eventId" value="<%=String.valueOf(nEvent.getIdEvent())%>"/>
                <input id="button" type="submit" name="message" value="message"/></p>
            </form>

            </fieldset>
                
        <%      } else { %>
            <h3>Il faut se loguer pour commenter...</h3>
        <%      } %>
        


            <h3>Commentaires</h3>
        <%
            if (!comments.isEmpty()) {

                java.util.Iterator it3 = comments.iterator();
                while (it3.hasNext()) {
                    Comment comment = (Comment) it3.next();
                    %>
                    <p><label><%=comment.getUser().getUser()%>"></label><%= comment.getComment() %></p>
                    <%      }
            } else {
                out.print("<p>Pour le moment, personne n'a encore commenté cet event.</p>");
            }
        %>
        </div>



</body>
</html>